package com.example.desinger.designPattern.dutymodel;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.example.desinger.common.R;
import com.example.desinger.entity.HomeRemark;
import com.example.desinger.entity.StuHomeWork;
import com.example.desinger.service.StuHomeWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UpdateHomeworkScoreHandler extends AbstractHandler {
    @Autowired
    private StuHomeWorkService stuHomeWorkService;

    public UpdateHomeworkScoreHandler(StuHomeWorkService stuHomeWorkService) {
        this.stuHomeWorkService = stuHomeWorkService;
    }

    @Override
    public R<String> handle(HomeRemark homeRemark) {
        LambdaUpdateWrapper<StuHomeWork> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(StuHomeWork::getClassId, homeRemark.getClass_id())
                .eq(StuHomeWork::getStuId, homeRemark.getStu_id())
                .eq(StuHomeWork::getHomeWorkId, homeRemark.getStu_home_work_id());
        StuHomeWork stuHomeWork = new StuHomeWork();
        stuHomeWork.setScore(2);

        boolean update = stuHomeWorkService.update(stuHomeWork, lambdaUpdateWrapper);
        if (update) {
            return R.success("添加评论信息成功");
        }
        return R.error("未知错误");
    }
}
